VERSION 5.00
Begin VB.Form frmMinMaxInfo 
   Caption         =   "MinMaxInfo Subclassing Sample"
   ClientHeight    =   3195
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4680
   ClipControls    =   0   'False
   HasDC           =   0   'False
   ScaleHeight     =   3195
   ScaleWidth      =   4680
   StartUpPosition =   3  'Windows Default
   Begin VB.Label lblMessage 
      Height          =   195
      Left            =   210
      TabIndex        =   0
      Top             =   240
      Width           =   2775
   End
End
Attribute VB_Name = "frmMinMaxInfo"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'***************************************************************
' (c) Copyright 2000 Matthew J. Curland
'
' This file is from the CD-ROM accompanying the book:
' Advanced Visual Basic 6: Power Techniques for Everyday Programs
'   Author: Matthew Curland
'   Published by: Addison-Wesley, July 2000
'   ISBN: 0-201-70712-8
'   http://www.PowerVB.com
'***************************************************************
Option Explicit
Private m_SubClassMain As SubClassData
Private m_MinTrackSize As POINTAPI
Private Sub Form_Load()
    'Determine the minimum tracking size by using the
    'Label.AutoSize property to determine the size of the
    'control, then determine the pixel offset of the lower
    'right corner of the label from the upper left corner of
    'the window. Note that the Left property of a control is
    'relative to the client area of the window, which needs to
    'be adjusted by Width - ScaleWidth to get the position
    'relative to the true corner of the window. The equivalent
    'vertical calculation is done against the Top property.
    With lblMessage
        .AutoSize = True
        .Caption = "Try to resize the form to cover this text."
        m_MinTrackSize.x = (.Left + .Width + Width - ScaleWidth) \ Screen.TwipsPerPixelX
        m_MinTrackSize.y = (.Top + .Height + Height - ScaleHeight) \ Screen.TwipsPerPixelY
    End With
    SubClass m_SubClassMain, Me.hWnd, ObjPtr(Me), AddressOf RedirectMinMaxInfoWindowProc
End Sub

Private Sub Form_Unload(Cancel As Integer)
    UnSubClass m_SubClassMain, Me.hWnd
End Sub
Friend Function WindowProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Select Case uMsg
        Case WM_GETMINMAXINFO
            With g_DerefMinMaxInfo
                .Owner.SA.pvData = lParam
                'Read off the cached minimum tracking size.
                'All other values are preset by Windows.
                .pSA(0).ptMinTrackSize = m_MinTrackSize
            End With
            Exit Function 'Return 0 per MSDN
        'Add other messages here
    End Select
    WindowProc = CallWindowProc(m_SubClassMain.wndprocNext, hWnd, uMsg, wParam, lParam)
End Function

